package com.example.exception;

import com.example.common.CustomerException;
import com.example.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        log.error("捕获到了一个error调用" + e);
        return Result.error(501, e.getMessage(), "全局异常捕获--->>error被调用");
    }

    @ExceptionHandler(value = CustomerException.class)
    @ResponseBody
    public Result customererror(CustomerException e) {
        log.error("捕获到了一个customererror调用" + e);
        return Result.error(e.getCode(), e.getMsg(),"全局异常捕获--->>customererror被调用");
    }


}
